prefix = /usr
libdir = ${prefix}/lib
incdir = ${prefix}/include
library = libip2c.a
CC = gcc
CLFLAGS = -c -Os
CCFLAGS = -Os
CCLIBS = -lip2c
SOURCES = ip2c.c
AR = ar
ARFLAGS = rcs

all: $(library)
	@echo "Build complete."

install: $(all)
	@cp ip2c.h $(incdir)
	@cp $(library) $(libdir)
	@echo "Installed in $(incdir) and $(libdir)"

$(library):
	@$(CC) $(CLFLAGS) $(SOURCES)
	@$(AR) $(ARFLAGS) $(library) *.o

dbtools:
	@$(CC) $(CCFLAGS) -o tools/make_db tools/make_db.c $(CCLIBS)
	@$(CC) $(CCFLAGS) -o tools/read_db tools/read_db.c $(CCLIBS)
	@$(CC) $(CCFLAGS) -o tools/ip2c tools/ip2c.c $(CCLIBS)
	@echo "Tools compiled."

dbtools-clean:
	@rm tools/make_db tools/read_db tools/ip2c

clean: 
	@find . -name \*.lo | xargs rm -f
	@find . -name \*.o | xargs rm -f
	@find . -name \*.la | xargs rm -f
	@find . -name \*.a | xargs rm -f
	@find . -name \*.so | xargs rm -f
	@find . -name .libs -a -type d|xargs rm -rf
	@echo "Cleaned up."
	@rm tools/make_db tools/read_db
